package com.example.administrator.myapplication.set;

import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

import com.example.administrator.myapplication.BmobApplication;
import com.example.administrator.myapplication.R;
import com.example.administrator.myapplication.set.about.AboutMainFragment;

/**
 * Created by Administrator on 2018/1/14.
 */

public class UserinfoFragment extends Fragment {
    private Toolbar toolbar;
    private EditText ed_userName;
    private EditText ed_height;
    private EditText ed_weight;
    private EditText ed_school;
    private EditText ed_major;
    private EditText ed_grade;

    private Button bt_setUserInfo;

    private BmobApplication setUserInfo_apps;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        View view =inflater.inflate(R.layout.fragment_set_userinfo,container,false);
        toolbar = (Toolbar) getActivity().findViewById(R.id.toobar_set);
        toolbar.setNavigationIcon(R.mipmap.custom_back);
        toolbar.setTitle("个人资料");
        toolbar.setTitleMarginStart(35);
        toolbar.setTitleTextColor(Color.parseColor("#ffffff"));
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SetMainFragment fragment =new SetMainFragment();
                FragmentManager fm =getActivity().getFragmentManager();
                FragmentTransaction ft =fm.beginTransaction();
                ft.replace(R.id.fragment_setmain,fragment).commit();
            }
        });
        ed_userName = (EditText) view.findViewById(R.id.ed_userinfo_username);
        ed_height = (EditText) view.findViewById(R.id.ed_userinfo_height);
        ed_weight = (EditText) view.findViewById(R.id.ed_userinfo_weight);
        ed_school = (EditText) view.findViewById(R.id.ed_userinfo_school);
        ed_major = (EditText) view.findViewById(R.id.ed_userinfo_major);
        ed_grade = (EditText) view.findViewById(R.id.ed_userinfo_grade);

        bt_setUserInfo = (Button) view.findViewById(R.id.bt_setUserInfo_submit);

        setUserInfo_apps = new BmobApplication();

        String mUserName = ed_userName.getText().toString();
        final String mHeight = ed_height.getText().toString();
        final String mWeight = ed_weight.getText().toString();
        final String mSchool = ed_school.getText().toString();
        final String mMajor = ed_major.getText().toString();
        final String mGrade = ed_grade.getText().toString();
        bt_setUserInfo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                setUserInfo_apps.setBody_height_result(mHeight);
                setUserInfo_apps.setBody_weight_result(mWeight);
                setUserInfo_apps.setSchool(mSchool);
                setUserInfo_apps.setGrade(mGrade);
                setUserInfo_apps.setMajor(mMajor);
            }
        });
        return view;
    }
}
